package com.xuecheng.learning.controller;

import com.xuecheng.commons.model.dto.LearningProgressDto;
import com.xuecheng.commons.model.dto.RecordDto;
import com.xuecheng.commons.model.vo.CourseRecordVo;
import com.xuecheng.commons.model.vo.ResourceVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.learning.service.CourseRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;

/**
 * <p>
 * 选课记录前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class CourseRecordController {

    @Autowired
    private CourseRecordService  courseRecordService;

    //查询选课记录
    @GetMapping("/courseRecord/myCourseRec/{coursePubId}")
    public ResponseResult<CourseRecordVo> myCourseRecord(@PathVariable("coursePubId")Long coursePubId){
        return courseRecordService.myCourseRecord(coursePubId);
    }

    /*//用户支付成功，保存选课记录
    @PostMapping("/courseRecord/saveRecord")
    public ResponseResult saveRecord(@RequestBody RecordDto recordDto) throws IOException {
        return courseRecordService.saveRecord(recordDto);
    }*/

    //课程详情获取媒资地址
    @GetMapping("/courseRecord/resource-url")
    public ResponseResult<ResourceVo> resourceUrl(Long coursePubId, Long mediaId, Long teachplanId) throws Exception {
        return courseRecordService.resourceUrl(coursePubId,mediaId,teachplanId);
    }

    //记录学习进度
    @PostMapping("/courseRecord/progress")
    public ResponseResult progress(@RequestBody LearningProgressDto progressDto) throws IOException {
        return courseRecordService.progress(progressDto);
    }
}
